package com.hh.item.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hh.item.pojo.Message;
import com.hh.item.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yangfan
 * @date 2020/3/8 19:25
 * @description
 */
@RestController
@RequestMapping("/wb")
public class MessageController {

    @Autowired
    private IMessageService messageService;

    /**
     * @param userId
     * @return java.util.List<com.hh.item.pojo.Message>
     * @description 分页获取用户主页微博（关注人/自己）
     */
    @GetMapping("/{userId}/{pageNum}/{pageSize}")
    public PageInfo<Message> mainMsgs(@PathVariable Integer userId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) throws IOException {
        return messageService.mainMsgs(userId, pageNum, pageSize);
    }

    /**
     * @param message
     * @return java.lang.String
     * @description 用户发原创微博
     */
    @PostMapping("/sent")
    public String sent(@RequestBody Message message) {
        return messageService.sent(message);
    }

    /**
     * @param userId
     * @param pageNum
     * @param pageSize
     * @return com.github.pagehelper.PageInfo<com.hh.item.pojo.Message>
     * @description 获取用户微博
     */
    @GetMapping("/one/{userId}/{pageNum}/{pageSize}")
    public PageInfo<Message> getMsgs(@PathVariable Integer userId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) throws IOException {
        return messageService.getMsgs(userId, pageNum, pageSize);
    }

    /**
     * @param userId
     * @param msgId
     * @return java.lang.String
     * @description 更改点赞状态
     */
    @GetMapping("/like/{userId}/{msgId}")
    public String like(@PathVariable Integer userId, @PathVariable Integer msgId) {
        return messageService.like(userId, msgId);
    }

    /**
     * @param userId
     * @param msgId
     * @return java.lang.String
     * @description 更改收藏状态
     */
    @GetMapping("/collect/{userId}/{msgId}")
    public String collect(@PathVariable Integer userId, @PathVariable Integer msgId) {
        return messageService.collect(userId, msgId);
    }

    /**
     * @param userId
     * @param msgId
     * @return java.lang.String
     * @description 删除微博
     */
    @DeleteMapping("/delete/{userId}/{msgId}")
    public String delete(@PathVariable Integer userId, @PathVariable Integer msgId) {
        return messageService.delete(userId, msgId);
    }

    /**
     * @param userId
     * @return java.util.List<com.hh.item.pojo.Message>
     * @description 获取收藏微博
     */
    @GetMapping("/myCollect/{userId}")
    public List<Message> myCollect(@PathVariable Integer userId) {
        return messageService.myCollect(userId);
    }

    @GetMapping("/other/{targetId}/{userId}/{pageNum}/{pageSize}")
    public PageInfo<Message> onesMsgs(@PathVariable Integer targetId, @PathVariable Integer userId, @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        return messageService.onesMsgs(targetId,userId, pageNum, pageSize);
    }
}
